﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HackerRank.Puzzles
{
    // https://www.hackerrank.com/challenges/utopian-tree

    class UtopianTreeSolver
    {
        internal int[] Solve(ref int[] input)
        {
            // Initial tree height
            int initialTreeHeight = 1;

            //create output array size
            int[] output = new int[input.Count() - 1];

            // Traverse over test cases which are first number in array
            for (int i = 1; i <= input[0]; i++)
            {
                int treeHeight = initialTreeHeight;

                for (int j = 1; j <= input[i]; j++) //Loop over growth cycles
                {
                    if (j % 2 != 0)
                    {
                        treeHeight += treeHeight;
                    }
                    else
                    {
                        treeHeight += 1;
                    }
                }

                output[i-1] = treeHeight;
            }
            return output;
        }
    }
}
